home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / nextgo23.taz / nextgo23 / NeXTGo / findwinr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  1.5 KB  |  72 lines

  1. #include "comment.header"
  2.  
  3. #define EMPTY 0
  4.  
  5. extern unsigned char p[19][19], l[19][19];
  6. extern int currentStone, opposingStone, MAXX, MAXY;
  7. extern int lib;
  8. extern void countlib(int,int,int);
  9. extern void initmark();
  10. extern int findopen(int,int,int[],int[],int,int,int*);
  11.  
  12. int findwinner(int *i, int *j, int *val)
  13.      /* find opponent piece to capture or attack */
  14. {
  15.   int m, n, ti[3], tj[3], tval, ct, u, v, lib1;
  16.   
  17.   *i = -1;   *j = -1;   *val = -1;
  18.   
  19.   /* find opponent with liberty less than four */
  20.   for (m = 0; m < MAXX; m++)
  21.     for (n = 0; n < MAXY; n++)
  22.       if ((p[m][n] == opposingStone) && (l[m][n] < 4))
  23.     {
  24.       ct = 0;
  25.       initmark();
  26.       if (findopen(m, n, ti, tj, opposingStone, l[m][n], &ct))
  27.         {
  28.           if (l[m][n] == 1)
  29.         {
  30.           if (*val < 120)
  31.             {
  32.               *val = 120;
  33.               *i = ti[0];
  34.               *j = tj[0];
  35.             }
  36.         }
  37.           else
  38.         for (u = 0; u < l[m][n]; u++)
  39.           for (v = 0; v < l[m][n]; v++)
  40.             if (u != v)
  41.               {
  42.             lib = 0;
  43.             countlib(ti[u], tj[u], currentStone);
  44.             if (lib > 0) /* valid move */
  45.               {
  46.                 lib1 = lib;
  47.                 p[ti[u]][tj[u]] = currentStone;
  48.                 /* look ahead opponent move */
  49.                 lib = 0;
  50.                 countlib(ti[v], tj[v], opposingStone);
  51.                 if ((lib1 == 1) && (lib > 0))
  52.                   tval = 0;
  53.                 else
  54.                   tval = 120 - 20 * lib;
  55.                 if (*val < tval)
  56.                   {
  57.                 *val = tval;
  58.                 *i = ti[u];
  59.                 *j = tj[u];
  60.                   }
  61.                 p[ti[u]][tj[u]] = EMPTY;
  62.               }
  63.               }
  64.         }
  65.     }
  66.   if (*val > 0)    /* find move */
  67.     return 1;
  68.   else  /* fail to find winner */
  69.     return 0;
  70. }  /* end findwinner */
  71.  
  72.